package com.maomao;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @description:
 * @auther: 雪域青竹
 * @version: 1.0
 * @create 2024/3/29 17:21
 */
public class Application {
    public static void main(String[] args) throws IOException {


        /*
         *  自定义server 服务端
         *  获取浏览器的信息。并反馈信息。
         */
        System.out.println("my server run....");
        ServerSocket ss = new ServerSocket(9090);

            Socket s = ss.accept();
            System.out.println(s.getInetAddress().getHostAddress() + "....connected");

            //读取客户端的数据。
            InputStream in = s.getInputStream();
            byte[] buf = new byte[1024 * 1024 * 100];
            int len = in.read(buf);
            String text = new String(buf, 0, len);
            System.out.println(text);

            //给客户端回馈数据。
            PrintWriter out = new PrintWriter(s.getOutputStream(), true);


            out.println("HTTP/1.1 200 OK");
            out.println("Server: Apache-Coyote/1.1");
            out.println("Content-Type: text/html;charset=utf-8");
            out.println("Transfer-Encoding: chunked");
            out.println(" Date: Mon, 01 Apr 2024 01:54:38 GMT");
            out.println();
            out.println("<font color='red' size='7' face='楷书'>雪域青竹</font>");

        s.close();
        ss.close();
    }

    public static void a(String[] args) throws IOException {
        ServerSocket server = new ServerSocket(9090);
        Socket socket = server.accept();
        byte[] buf = new byte[2048];
        InputStream inputStream = socket.getInputStream();
        int len = inputStream.read(buf);
        String text = new String(buf, 0, len);
        System.out.println(text);
        PrintWriter pw = new PrintWriter(socket.getOutputStream(), true);
        pw.println("雪域青竹");
    }
}
